#!/bin/sh
red=`tput setaf 1`
green=`tput setaf 2`
reset=`tput sgr0`

counter=0

for FILE in `git diff --name-only --cached`; do

    if [[ $FILE == *".sh"* || $FILE == *"pnpm-lock.yaml"* || $FILE == *".md"* || $FILE == *"uni_modules"* ]]; then
      continue
    fi

    grep --no-messages 'debugger\|console\|alert(' $FILE 2>&1 >/dev/null
    if [ $? -eq 0 ]; then
      let counter+=1
      echo "${red}${counter}. ${FILE}${reset}"
    fi

done

if [ $counter -gt 0 ]; then
  echo "🤖 ${green}以上文件包含debugger or console or alert，请删除后再提交${reset}"
  exit 1
fi
